﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Core.Model;
using PersonalHealth.Data.Data;
using Core.Service;
using System.Collections;
using System.Threading;
using PersonalHealth.Data.Model;

namespace PersonHealth.View
{
    /// <summary>
    /// TreeSelectPage.xaml 的交互逻辑
    /// </summary>
    public partial class TreeSelectPage : Page
    {
        public TreeSelectPage()
        {
            InitializeComponent();
        }

        public TreeSelectPage(IItem parent, Func<object, IEnumerable> onGetData, Action<object> onSelected) : this()
        {
            this.OnGetData = onGetData;
            this.OnSelected = onSelected;
            MessageList.ItemsSource = OnGetData(parent);
        }

        Func<object, IEnumerable> OnGetData;
        Action<object> OnSelected;

        private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            INode<Department> obj = (INode<Department>)MessageList.SelectedItem;
            if (obj.Leaf == true)
            {
                if (MessageList.SelectedItem != null)
                    OnSelected(MessageList.SelectedItem);
                //NavigationService.Navigate(new Uri("View/PersonInfoPage.xaml", UriKind.RelativeOrAbsolute));
                NavigationService.Content = new PersonInfoPage();
            }
            else
            {
                MessageList.ItemsSource = OnGetData(obj);
            }
        }
    }
}
